#include "mycaculatedlg.h"

MyCaculateDlg::MyCaculateDlg():clg(new Ui::CaculateDialog())
{
    clg->setupUi(this);

    QObject::connect(clg->lineEdit,SIGNAL(textChanged(QString)),this,
                     SLOT(on_lineEdit_textChanged(QString)));
    QObject::connect(clg->lineEdit_2,SIGNAL(textChanged(QString)),
                     this,SLOT(on_lineEdit_textChanged(QString)));
    QObject::connect(clg->pushButton,SIGNAL(clicked()),
                     this,SLOT(on_pushButton_clicked()));
}

void MyCaculateDlg::on_lineEdit_textChanged(const QString &arg1)
{
    bool b1 = false,b2 = false;
    clg->lineEdit->text().toDouble(&b1);
    clg->lineEdit_2->text().toDouble(&b2);
    clg->pushButton->setEnabled(b1 && b2);
}

void MyCaculateDlg::on_lineEdit_2_textChanged(const QString &arg1)
{
    bool b1 = false,b2 = false;
    clg->lineEdit->text().toDouble(&b1);
    clg->lineEdit_2->text().toDouble(&b2);
    clg->pushButton->setEnabled(b1 && b2);
}

void MyCaculateDlg::on_pushButton_clicked()
{
    double a = clg->lineEdit->text().toDouble();
    double b = clg->lineEdit_2->text().toDouble();
    double sum = a + b;
    QString str = QString::number(sum);

    clg->lineEdit_3->setText(str);
}
